package com.wtz.temptest;

/**
 * Date: 2020/11/6
 * Company: www.dtstack.com
 *
 * @author tiezhu
 * threadLocal
 */
public class TempDemoFour {

    public static class MyRunnable implements Runnable {

        private final ThreadLocal<Object> threadLocal = new ThreadLocal<>();

        @Override
        public void run() {
            threadLocal.set(Math.random() * 1000D);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(threadLocal.get());
        }
    }

    public static void main(String[] args) {
        MyRunnable target = new MyRunnable();
        Thread threadOne = new Thread(target);
        Thread threadTwo = new Thread(target);
        threadOne.start();
        threadTwo.start();
    }
}
